package de.joergviola.mobj.client.database;

import java.io.Serializable;
import java.util.Arrays;
import java.util.logging.Logger;

import com.google.code.gwt.database.client.SQLTransaction;

import de.joergviola.mobj.shared.Entity;

public class Delete<T extends Serializable> {

	private static final Logger log = Logger.getLogger("Delete");
	private String sql;
	private Object[] args;

	public Delete(Entity<T> entity, String where) {
		this.sql = "DELETE FROM " + entity.getEntityName();
		if (where != null && where.length() > 0) {
			this.sql += " WHERE " + where;
		}
	}

	public void execute(SQLTransaction tx) {
		log.info(sql + " : " + Arrays.toString(args));
		tx.executeSql(getSQL(), getArgs());
	}

	private String getSQL() {
		return sql;
	}

	public Object[] getArgs() {
		return args;
	}

	public void setArgs(Object[] args) {
		this.args = args;
	}

}
